<?php
    header('Access-Control-Allow-Origin: *');
    header('Content-Type:application/json;charset=utf-8');
    $con = mysqli_connect("127.0.0.1", "root", "root", "mydb");
    $uId = $_GET['uid'];
    $status = $_GET['status'];
    $list = array();
    if($status == 'student'){
        $sql = "SELECT l.l_id,l.l_name,t.t_name,l.l_time,l.l_place,ls.state FROM stu_info as s INNER JOIN lessonStu as ls on s.stu_id = ls.s_id INNER JOIN lesson as l on l.l_id = ls.l_id INNER JOIN tch_info as t on t.t_id = l.teacher_id WHERE s.stu_id = '$uId' AND ls.state = 'review' OR ls.state = 'fail';";
        $res = mysqli_query($con,$sql);
        while($row = mysqli_fetch_array($res)){
            $item = array(
                'l_id' => $row['l_id'],
                'l_name' => $row['l_name'],
                't_name' => $row['t_name'],
                'l_time' => $row['l_time'],
                'l_place' => $row['l_place'],
                'state' => $row['state']
            );
            array_push($list,$item);
        }
    }else if($status == 'teacher'){
        $sql = "SELECT s.stu_name,l.l_name,ls.id from lessonStu as ls inner join stu_info as s on ls.s_id = s.stu_id inner join lesson as l on ls.l_id = l.l_id inner join tch_info as t on l.teacher_id = t.t_id where t.t_id = '$uId' and ls.state = 'review';";
        $res = mysqli_query($con,$sql);
        while($row = mysqli_fetch_array($res)){
            $item = array(
                'stuName' => $row['stu_name'],
                'className' => $row['l_name'],
                'id' => $row['id']
            );
            array_push($list,$item);
        }
    }
    echo json_encode(array(
        'list'=>$list,
    ));
    mysqli_close($con);
?>